//
//  Utility.m
//

#import "Utility.h"

#define DATA_CACHE @"DATA_CACHE_%@_%@"

@implementation Utility

+ (UILabel *)createLabel:(UIFont *)textFont color:(UIColor *)textColor{
    UILabel *label = [[UILabel alloc] init];
    label.textColor = textColor;
    label.backgroundColor = [UIColor clearColor];
    label.font = textFont;
    return label;
}

#pragma mark - store
+ (void)saveDataWithKey:(NSString *)key ofValue:(id)value{
    NSString *k = [NSString stringWithFormat:DATA_CACHE, @"", key];
    [[NSUserDefaults standardUserDefaults] setObject:value forKey:k];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (void)clearDataWithKey:(NSString *)key{
    NSString *k = [NSString stringWithFormat:DATA_CACHE, @"", key];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:k];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (id)getDataWithKey:(NSString *)key{
    NSString *k = [NSString stringWithFormat:DATA_CACHE, @"", key];
    return [[NSUserDefaults standardUserDefaults] objectForKey:k];
}

+ (void)saveEntityWithKey:(NSString *)key ofValue:(id)value{
    NSData *entity = [NSKeyedArchiver archivedDataWithRootObject:value];
    [self saveDataWithKey:key ofValue:entity];
}

+ (id)getEntityWithKey:(NSString *)key{
    NSData *entity = [self getDataWithKey:key];
    return [NSKeyedUnarchiver unarchiveObjectWithData:entity];
}



@end
